package com.ruoyi.service.dict.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.service.dict.entity.DictDataEntity;
import com.ruoyi.service.dict.mapper.DictDataMapper;
import com.ruoyi.service.dict.service.DictDataService;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 字典数据表 服务实现类
 * </p>
 *
 * @author zhanglianbao
 * @since 2025-10-04
 */
@Service
public class DictDataServiceImpl extends ServiceImpl<DictDataMapper, DictDataEntity>
    implements DictDataService {

  @Override
  public List<DictDataEntity> listByDictType(String dictType) {
    final LambdaQueryWrapper<DictDataEntity> query = effectQuery().eq(
            DictDataEntity::getDictType, dictType)
        .orderByAsc(DictDataEntity::getDictSort);
    return Optional.ofNullable(this.list(query)).orElseGet(ArrayList::new);
  }

  private LambdaQueryWrapper<DictDataEntity> effectQuery() {
    return new LambdaQueryWrapper<DictDataEntity>()
        .eq(DictDataEntity::getStatus, 0);
  }
}
